<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('出库管理列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <input type="hidden" id="treeId"  name="deptId" />
                <input id="categoryTreeId"  name="params[thingId]" type="hidden"/>
                <input id="thingTypeId"  name="thingTypeId" type="hidden"/>
                <div class="select-list">
                    <ul>
                        <li>
                            <label>行名称：</label>
                            <input readonly="readonly"  onclick="selectDeptTree()" id="treeName" type="text" placeholder="请选择归属行" >
                        </li>
                        <li>
                            <label>物品目录：</label>
                            <input readonly="readonly" onclick="selectCategoryTree()" id="categoryTreeName" type="text" placeholder="请选择物品分类" >
                        </li>
                        <li>
                            <label style="width: 100px">物品名称：</label>
                            <input type="text" name="createName"/>
                        </li>
                        <li>
                            <label>物品信息：</label>
                            <input type="text" name="mohu"/>
                        </li>
                        <li>
                            <label>收支项目：</label>
                            <input readonly="readonly" onclick="selectThingTypeTree()" id="thingType" type="text" placeholder="请选择收支项目" >
                        </li>
                        <li>
                            <label>出库人：</label>
                            <input type="text" name="createBy"/>
                        </li>
<!--                        <li>-->
<!--                            <label>出库类型：</label>-->
<!--                            <select name="outboundType" th:with="type=${@dict.getType('f_outbound_type')}">-->
<!--                                <option value="">所有</option>-->
<!--                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"-->
<!--                                        th:value="${dict.dictValue}"></option>-->
<!--                            </select>-->
<!--                        </li>-->
                        <li class="select-time">
                            <label>出库时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="chongzhi()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
<!--            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="financial:fOutbound:add">-->
<!--                <i class="fa fa-plus"></i> 添加-->
<!--            </a>-->
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="financial:fOutbound:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="financial:fOutbound:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">

    var editFlag = [[${@permission.hasPermi('financial:fOutbound:edit')}]];
    var removeFlag = [[${@permission.hasPermi('financial:fOutbound:remove')}]];

    var outboundTypeDatas = [[${@dict.getType('f_outbound_type')}]];

    var prefix = ctx + "financial/fOutbound";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl:  prefix + "/export",
            detailUrl: prefix + "/detail/{id}",
            modalName: "出库管理",
            columns: [{
                checkbox: true
            },
                {
                    field: 'outId',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'deptName',
                    title: '行名称'
                },
                {
                    field: 'thingName',
                    title: '物品目录'
                },
                {
                    field: 'thingType',
                    title: '收支项目'
                },
                {
                    field: 'createName',
                    title: '物品名称'
                },
                {
                    field: 'mohu',
                    title: '物品信息',
                },
                {
                    field: 'shuliang',
                    title: '数量'
                },
                {
                    field: 'pingjunSunhao',
                    title: '人均消耗',
                    formatter: function (value, row, index) {
                        var str = ""
                        if(row.averageSunhao){
                            if(parseFloat(value) > parseFloat(row.averageSunhao)){
                                str = "<span style='color: #ED5565'>"+value+"</span>";
                            }else{
                                str = "<span style='color: #1AB394'>"+value+"</span>";
                            }
                        }else{
                            str = ""+value
                        }
                        return str
                    },
                    sortable: true
                },
                {
                    field: 'averageSunhao',
                    title: '平均消耗',
                },
                // {
                //     field: 'outboundType',
                //     title: '出库类型',
                //     formatter: function (value, row, index) {
                //         return $.table.selectDictLabel(outboundTypeDatas, value);
                //     }
                // },
                {
                    field: 'recipientBy',
                    title: '领用人'
                },
                {
                    field: 'createBy',
                    title: '出库人'
                },
                {
                    field: 'outTime',
                    title: '出库时间',
                    sortable: true
                },
                {
                    field: 'remark',
                    title: '备注',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value, 10, "open");
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.outId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.outId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        console.log(options)
        $.table.init(options);
    });

    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/user/selectDeptTree/" + deptId;
        var options = {
            title: '选择行',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }
    function doSubmit(index, layero){
        var body = $.modal.getChildFrame(index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    function selectCategoryTree() {
        var treeId = $("#categoryTreeId").val();
        var url = ctx + "financial/fThing/selectFThingCategoryTree/";
        var options = {
            title: '选择物品',
            width: "380",
            url: url,
            callBack: doSubmit2
        };
        $.modal.openOptions(options);
    }
    function doSubmit2(index, layero){
        var body = $.modal.getChildFrame(index);
        $("#categoryTreeId").val(body.find('#treeId').val());
        $("#categoryTreeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    function selectThingTypeTree() {
        var treeId = $("#categoryTreeId").val();
        var url = ctx + "financial/thingType/selectThingTypeTree/";
        var options = {
            title: '选择收支项目',
            width: "380",
            url: url,
            callBack: doSubmit3
        };
        $.modal.openOptions(options);
    }
    function doSubmit3(index, layero){
        var body = $.modal.getChildFrame(index);
        $("#thingTypeId").val(body.find('#treeId').val());
        $("#thingType").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    function chongzhi() {
        $("#treeId").val("")
        $("#categoryTreeId").val("")
        $("#thingType").val("")
        $("#thingTypeId").val("")
        $.form.reset()
    }

    function daochu2() {
        $.modal.confirm("确定导出所有出库管理吗？", function() {
            var dataParam = $("#formId").serializeArray();
            $.modal.loading("正在导出数据，请稍候...");
            $.post(prefix + "/export2", dataParam, function(result) {
                if (result.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        });
    }


</script>
</body>
</html>